﻿using CompanyManageSystem.DLL;
using CompanyManageSystem.Service;
using DevExpress.XtraSplashScreen;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CompanyManageSystem.UI.Main
{
    public partial class Frm_Login : BaseXtraForm
    {
        /// <summary>
        /// 构造方法
        /// </summary>
        public Frm_Login()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 窗体加载完成
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Frm_Login_Load(object sender, EventArgs e)
        {
            timer1.Enabled = true;
           
        }

        /// <summary>
        /// 确定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Btn_OK_Click(object sender, EventArgs e)
        {
            AppService aservice = new AppService();

            string userName = UserEdit.Text;
            string password = PasswordEdit.Text;
 
            bool isExist = aservice.LoginByNameAndPass(userName,password);

            //Action action = () =>
            //{
            //    if (isExist)
            //    {
            //        //打开另一个窗口的同时关闭当前窗口
            //        Thread th = new Thread(delegate () { new Frm_Main().ShowDialog(); });
            //        th.Start();
            //        this.Close();
            //        //th.Abort();
            //    }
            //};
            //action.Invoke();
            if (isExist)
            {
                var id = aservice.GetIDByNameAndPass(userName, password);
                Frm_Mains frm = new Frm_Mains(id);
                this.Hide();
                frm.ShowDialog();
                this.Close();
            }
            else
            {
                dxErrorProvider1.SetIconAlignment(PasswordEdit, ErrorIconAlignment.MiddleRight);
                dxErrorProvider1.SetError(PasswordEdit, "密码不正确!", DevExpress.XtraEditors.DXErrorProvider.ErrorType.Warning);
            }

        }

        /// <summary>
        /// 取消
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Btn_Cancle_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        /// <summary>
        /// 提示栏
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timer1_Tick(object sender, EventArgs e)
        {
            LabelTip.Left += 1;
            if (LabelTip.Right > this.Width + LabelTip.Width)
            {
                LabelTip.Left = -LabelTip.Width;
            }
        }

        
    }
}
